package cn.gzsxt.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.gzsxt.mapper.RoleMapper;
import cn.gzsxt.service.RoleService;
import cn.gzsxt.utils.Page;

@Service
public class RoleServiceImpl implements RoleService{
	
	@Autowired
	private RoleMapper roleMapper;

	@Override
	public Map<String, Object> addRole(Map<String, Object> role) {
		int count = roleMapper.insert(role);
		if(count>0){
			return role;
		}
		return null;
	}

	@Override
	public int deleteRoleByIds(Object... roleIds) {
		return roleMapper.deleteByIds(roleIds);
	}

	@Override
	public Map<String, Object> editRole(Map<String, Object> role) {
		int count = roleMapper.updateForNotnull(role);
		if (count>0) {
			return role;
		}
		return null;
	}

	@Override
	public List<Map<String, Object>> findAllRole() {
		return roleMapper.findAll();
	}

	@Override
	public Page findRoleByConditionToPage(Map<String, Object> condition, int index, int size) {
		//构建一个分页对象
		//1.获得总记录数据
		long count = roleMapper.count(condition);
		//2.获得分页数据
		int start=index*size;
		List<Map<String, Object>> moduarls = roleMapper.findByConditionAndPage(condition, start, size);
		//3.构建分页对象
		Page page=new Page(index, size, count, moduarls);
		//4.返回分页对象
		return page;
	}

	@Override
	public Map<String, Object> findRoleById(Object roleId) {
		
		return roleMapper.findById(roleId);
	}


}
